<template>
  <div>
    <el-row :gutter="10">
      <el-col :span="12">
        <el-card>
          <div style="width: 100%; height: 400px" id="line"></div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card>
          <div style="width: 100%; height: 400px" id="bar"></div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="10" style="margin: 10px 0">
      <el-col :span="12">
        <el-card>
          <div style="width: 100%; height: 400px" id="pie"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts'

const option = {
  title: {
    text: '订单销售的趋势图',
    left: 'center',
  },
  tooltip: {
    trigger: 'axis',
  },
  legend: {
    left: 'left',
  },
  xAxis: {
    type: 'category',
    data: ['星期一', '星期二', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  },
  yAxis: {
    type: 'value',
  },
  series: [
    {
      name: '库存',
      data: [850, 230, 224, 218, 135, 147, 260],
      type: 'line',
    },
    {
      name: '金额',
      data: [420, 400, 650, 880, 470, 1105, 1030],
      type: 'line',
    },
    {
      name: '销量',
      data: [99, 140, 150, 480, 370, 610, 130],
      type: 'line',
    },
  ],
}

const option2 = {
  title: {
    text: '订单销售的柱状图',
    left: 'center',
  },
  tooltip: {
    trigger: 'axis',
  },
  legend: {
    left: 'left',
  },
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  },
  yAxis: {
    type: 'value',
  },
  series: [
    {
      name: '金额',
      data: [1020, 400, 650, 880, 1470, 1105, 1200],
      type: 'bar',
    },
    {
      name: '销量',
      data: [899, 240, 350, 480, 370, 610, 830],
      type: 'bar',
    },
  ],
}

export default {
  name: 'Charts',
  data() {
    return {}
  },
  mounted() {
    // 等待页面的元素全部加载完成之后再初始化

    // 折线图
    let lineDom = document.getElementById('line')
    let lineChart = echarts.init(lineDom)
    lineChart.setOption(option)

    let barDom = document.getElementById('bar')
    let barChart = echarts.init(barDom)
    barChart.setOption(option2)
  },
  methods: {},
}
</script>

<style scoped></style>
